package com.design.strategy.template.dao;



import com.design.strategy.template.entity.Member;
import com.design.strategy.template.framework.JdbcTemplate;
import com.design.strategy.template.framework.RowMapper;

import javax.sql.DataSource;
import java.util.List;

/**
 * 数据库操作对象
 *
 * @Author: cong zhi
 * @CreateDate: 2021/4/3 9:17
 * @UpdateUser: cong zhi
 * @UpdateDate: 2021/4/3 9:17
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class MemberDao extends JdbcTemplate {
    public MemberDao(DataSource dataSource) {
        super(dataSource);
    }


    public List<?> selectAll() {
        String sql = "select * from t_member";
        return super.executeQuery(sql, (RowMapper<Member>) (rs, rowNum) -> {
            Member member = new Member();
            member.setUsername(rs.getString("username"));
            member.setPassword(rs.getString("password"));
            member.setAge(rs.getInt("age"));
            member.setNickname(rs.getString("nickname"));
            return member;
        }, null);
    }


}
